package com.hqyj.springBoot.modules.common.service.impl;

import com.hqyj.springBoot.modules.common.dao.ExceptionLogDao;
import com.hqyj.springBoot.modules.common.entity.ExceptionLog;
import com.hqyj.springBoot.modules.common.service.ExceptionLogService;
import com.hqyj.springBoot.modules.common.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
public class ExceptionLogServiceImpl implements ExceptionLogService {

    @Autowired
    private ExceptionLogDao exceptionLogDao;

    @Override
    @Transactional
    public Result<ExceptionLog> insertExceptionLog(ExceptionLog exceptionLog) {

        ExceptionLog temp = exceptionLogDao.getExceptionLogByParam(
                exceptionLog.getPath(),
                exceptionLog.getMethodName(),
                exceptionLog.getExceptionType()
        );
        if (temp != null){
            return new Result<>(Result.ResultStatus.SUCCESS.code, "异常已经记录");
        }
        exceptionLog.setCreateDate(LocalDateTime.now());
        exceptionLog.setUpdateDate(LocalDateTime.now());

        exceptionLogDao.insertExceptionLog(exceptionLog);

        return new Result<>(Result.ResultStatus.SUCCESS.code, "插入成功",exceptionLog);
    }
}
